<template>
  <views class="enterprise_statistic_detail">
    <viewTitle :title="'明细详情'" :border="false"></viewTitle>

    <!-- 业务订单号  业务批次号 - 业务类型 创建时间 -->
    <div class="search flex flexC">
      <!-- 业务订单号  业务批次号 - 业务类型 创建时间 -->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR center">
          <div class="their_facilitator flex flexR center">
            <el-form-item label="业务订单号:">
              <el-input v-model="business_order" placeholder="请输入业务订单号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="pay_state flex flexR center">
            <el-form-item label="业务批次号:">
              <el-input v-model="business_batch" placeholder="请输入业务批次号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="pay_state flex flexR center">
            <el-form-item label="业务类型:">
              <el-select v-model="business_type" clearable placeholder="请选择">
                <el-option
                  v-for="item in business_type_list"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <el-form ref="form" label-width="auto" :inline="true">
      <div class="pay_btn flex">
        <!-- 创建时间 -->
        <div class="creation_time flex flexR center">
          <el-form-item label="创建时间:">
            <el-date-picker
              v-model="create_time"
              value-format="timestamp"
              type="datetimerange"
              align="right"
              :default-time="['0:00:00','23:59:59']"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </el-form-item>
        </div>
        <!-- 按钮（查询、重置、）   -->
        <el-form-item>
          <div class="flex flexR pay_btn_list">
            <el-button type="primary" @click="getData" icon="el-icon-search">查询</el-button>
            <el-button @click="reSet" icon="el-icon-refresh">重置</el-button>
            <el-button type="danger" icon="el-icon-download" @click="exportExcel">导出列表</el-button>
          </div>
        </el-form-item>
      </div>
    </el-form>

    <div class="search_input flex flexR center">
      <div :style="{marginLeft:'15px'}" class="show-title-money flex flexR">
        <div class="flex flexR">
          <div>交易笔数</div>
          <div class="price">{{pagination.total_count}}</div>
          <div>笔</div>
        </div>
        <div class="flex flexR">
          <div>交易金额(元)</div>
          <div class="price">￥{{pagination.summy ? $splitK(pagination.summy) : ''}}</div>
        </div>
      </div>
    </div>

    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column type="index" fixed label="序号" width="100"></el-table-column>
        <el-table-column prop="enterprise_sn" fixed label="企业编号" width="200"></el-table-column>
        <el-table-column prop="enterprise_name" label="企业名称" width="200"></el-table-column>
        <el-table-column prop="enterprise_order_sn" label="批次号" width="200"></el-table-column>
        <el-table-column prop="enterprise_order_ext_sn" label="订单号" width="200"></el-table-column>
        <el-table-column prop="real_money" label="交易金额" width="200"></el-table-column>
        <el-table-column prop="process_commission" label="手续费" width="200"></el-table-column>
        <el-table-column prop="plat_money" label="到账金额" width="200"></el-table-column>
        <el-table-column prop="order_type" label="订单类型" width="200"></el-table-column>
        <el-table-column prop="updated_time" label="操作时间" width="200"></el-table-column>
        <el-table-column prop="pre_balance" label="账前余额" width="200"></el-table-column>
        <el-table-column prop="after_balance" label="账后余额" width="200"></el-table-column>
      </el-table>
    </div>
    <div class="flex flexR paging">
      <el-pagination
        style="background:#fff; padding:10px 0"
        background
        layout="total, sizes,prev, pager, next, jumper"
        @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
        @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pagination.page_size"
        :total="pagination.total_count"
        :current-page="pagination.current_page"
        :page-count="pagination.page_count"
      ></el-pagination>
    </div>
  </views>
</template>

<script>
export default {
  data() {
    return {
      business_type: null, // 业务类型
      business_type_list: [
        {
          label: "充值",
          value: "1"
        },
        {
          label: "代发",
          value: "2"
        }
      ], // 业务类型数组
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      business_batch: null, // 业务批次号
      business_order: null, // 业务订单号
      create_time: [], // 创建时间
      tableData: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      enterprise_id: "" // 企业ID
    };
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    getData(enterprise_id) {
      if (this.create_time && this.create_time[0]) {
        this.pay_time_start = this.create_time[0]/1000;
        this.pay_time_end = this.create_time[1]/1000;
      } else {
        this.pay_time_start = "";
        this.pay_time_end = "";
      }
      let data = this.$api.sendSync(this.$mapapi.f_myAccount, {
        enterprise_sn: this.business_order,
        enterprise_name: this.business_batch,
        pay_time_start: this.pay_time_start || "",
        pay_time_end: this.pay_time_end || "",
        enterprise_id: this.enterprise_id,
        pagination: this.pagination,
        order_type: this.business_type
      });
      if (data.code != 200 && data.code != 501) {
        this.$message.error(data.msg);
        return;
      }
      this.tableData = data.data.list || [];
      this.pagination = data.data.pagination || {};
      this.download_url = data.data.download_url || "";
    },
    reSet() {
      this.business_batch = null; // 业务批次号
      this.business_order = null; // 业务订单号
      this.create_time = []; // 创建时间
      this.business_type = null;
    },
    // 导出列表
    exportExcel() {
      this.$import_excal(this.download_url);
    }
  },
  mounted() {
    this.enterprise_id = this.$route.query.enterprise_id;
    this.$setRouteTitle();
    this.getData(this.enterprise_id);
  }
};
</script>


<style lang="less"  scope="true"  src="@/style/statistics/enterprise_statistic_detail.less">
</style>
